package com.woniuxy.creditsystem.common.mapper;



import com.woniuxy.creditsystem.common.bean.CustomerInfo;
import com.woniuxy.creditsystem.common.bean.DtoCus;
import com.woniuxy.creditsystem.common.util.PageRest;
import org.apache.ibatis.annotations.*;
import java.util.List;
/**
 * @author ：zhengbin
 * @date ：Created in 2020/12/10
 * @description：申请表mapper
 * @modified By：
 * @version: 1.0v
 */
@Mapper
public interface CustomerMapper {


    @ResultType(DtoCus.class)
    @Select("select id,name,telephone, identity_number as identityNumber,register_time as registerTime,last_visit_time lastVisitTime,remarks,loan_status  as loanStatus,customer_status  as customerStatus from customer_info")
    List<DtoCus> findAll();



    @ResultType(CustomerInfo.class)
    @Select("select id, name,telephone, identity_number as identityNumber,register_time as registerTime,last_visit_time lastVisitTime,remarks,loan_status  as loanStatus,customer_status  as customerStatus, " +
            "email ,nation,education,marital_status as maritalStatus,health_status as healthStatus,area_of_account as areaOfAccount, detailed_account_address as detailedAccountAddress," +
            "account_type as accountType,current_living_area as currentLivingArea,detailed_living_address  as detailedLivingAddress,check_in_time as checkInTime,front_photo_path as frontPhotoPath," +
            "reverse_photo_path as reversePhotoPath,handheld_photo_path as handheldPhotoPath  from customer_info where id=#{id}")
    CustomerInfo findById(long id);

    List<DtoCus> findByParams(@Param("p") PageRest req, @Param("dto")DtoCus dtoCus);




     @Options(
             useGeneratedKeys = true,
             keyProperty = "c.id"
     )
    @Insert("insert into customer_info (name,telephone,identity_number,register_time,last_visit_time,remarks,loan_status,customer_status,cumulative_loan," +
            "customer_note, email, nation, education,marital_status , health_status, area_of_account,detailed_account_address,account_type, current_living_area,detailed_living_address, check_in_time," +
            "front_photo_path,reverse_photo_path,  handheld_photo_path,work_company,  company_property, industry,job_level,entry_time,working_years," +
            "enterprise_size,enterprise_phone, enterprise_address, enterprise_detail_address ," +
            "monthly_salary,pay_method,payday, other_income , company_type  , established_time,family_monthly_income,monthly_income_of_spouse, " +
            "customer_monthly_income,family_monthly_expen,total_family_assets,total_household_debt,is_family_know_loan, spouse_name," +
            "spouse_phone,spouse_identity_number,spouse_enterprise_address, spouse_income ,immediate_family_member_name,common_contact_name," +
            "immediate_family_member_phone,immediate_family_member_company_address , common_contact_phone,common_contact_company_address,fk_product_id)" +
             "values(#{c.name},#{c.telephone},#{c.identityNumber},#{c.registerTime},#{c.lastVisitTime},#{c.remarks},#{c.loanStatus},#{c.customerStatus},#{c.cumulativeLoan}," +
            "#{c.customerNote} ,#{c.email} ,#{c.nation},#{c.education} ,#{c.maritalStatus},#{c.healthStatus},#{c.areaOfAccount},#{c.detailedAccountAddress} ,#{c.accountType},#{c.currentLivingArea},#{c.detailedLivingAddress},#{c.checkInTime}," +
            "#{c.frontPhotoPath},#{c.reversePhotoPath},#{c.handheldPhotoPath},#{c.workCompany} ,#{c.companyProperty} ,#{c.industry} ,#{c.jobLevel},#{c.entryTime} ,#{c.workingYears}," +
            "#{c.enterpriseSize} ,#{c.enterprisePhone} ,#{c.enterpriseAddress},#{c.enterpriseDetailAddress},#{c.monthlySalary},#{c.payMethod} ,#{c.payday} ,#{c.otherIncome},#{c.companyType},#{c.establishedTime} ,#{c.familyMonthlyIncome} ,#{c.monthlyIncomeOfSpouse}," +
            "#{c.customerMonthlyIncome},#{c.familyMonthlyExpen} ,#{c.totalFamilyAssets},#{c.totalHouseholdDebt}  ,#{c.isFamilyKnowLoan},#{c.spouseName} ," +
            "#{c.spousePhone},#{c.spouseIdentityNumber},#{c.spouseEnterpriseAddress} ,#{c.spouseIncome},#{c.immediateFamilyMemberName},#{c.commonContactName}," +
            "#{c.immediateFamilyMemberPhone} ,#{c.immediateFamilyMemberCompanyAddress}  ,#{c.commonContactPhone},#{c.commonContactCompanyAddress},#{c.fkProductId})")
    int saveCustomer(@Param("c") CustomerInfo customerInfo );


    @Update("<script>" +
            " update customer_info " +
            "<set>" +
            "<if test='c.name != null'> name = #{c.name}," +
            "</if>" +
            "<if test='c.telephone != null'> telephone = #{c.telephone}," +
            "</if>" +
            "<if test='c.identityNumber != null'> identity_number = #{c.identityNumber}," +
            "</if>" +
            "  <if test='c.registerTime != null'> register_time = #{c.registerTime}, " +
            "</if> " +
            " <if test='c.lastVisitTime != null'> last_visit_time = #{c.lastVisitTime}, " +
            "</if> " +
            " <if test='c.remarks != null'> remarks = #{c.remarks}, " +
            "</if> " +
            " <if test='c.loanStatus != null'> loan_status = #{c.loanStatus}, " +
            " </if> " +
            " <if test='c.customerStatus != null'> customer_status = #{c.customerStatus}, " +
            " </if> " +
            " <if test='c.cumulativeLoan != null'> cumulative_loan = #{c.cumulativeLoan}, " +
            " </if> " +
            " <if test='c.customerNote != null'> customer_note = #{c.customerNote}, " +
            " </if> " +
            " <if test='c.email != null'>  email = #{c.email}, " +
            " </if> " +
            " <if test='c.nation != null'> nation = #{c.nation}, " +
            " </if> " +
            " <if test='c.education  != null'> education  = #{c.education }, " +
            " </if> " +
            " <if test='c.maritalStatus != null'> marital_status = #{c.maritalStatus}, " +
            " </if> " +
            " <if test='c.healthStatus!= null'> health_status  = #{c.healthStatus}, " +
            " </if> " +
            " <if test='c.areaOfAccount!= null'> area_of_account  = #{c.areaOfAccount}, " +
            " </if> " +
            " <if test='c.detailedAccountAddress!= null'> detailed_account_address  = #{c.detailedAccountAddress}, " +
            "  </if> " +
            " <if test='c.accountType!= null'> account_type  = #{c.accountType}, " +
            " </if> " +
            " <if test='c.currentLivingArea!= null'> " +
            "current_living_area  = #{c.currentLivingArea}, </if> " +
            " <if test='c.detailedLivingAddress!= null'> " +
            "detailed_living_address  = #{c.detailedLivingAddress}, </if> " +
            " <if test='c.checkInTime != null'> check_in_time = #{c.checkInTime}, " +
            "</if> " +
            " <if test='c.frontPhotoPath!= null'> front_photo_path  = #{c.frontPhotoPath}, " +
            "</if> " +
            " <if test='c.reversePhotoPath != null'> reverse_photo_path  = #{c.reversePhotoPath}, " +
            "</if> " +
            " <if test='c.handheldPhotoPath != null'>  handheld_photo_path  = #{c.handheldPhotoPath}, " +
            "</if> " +
            " <if test='c.workCompany != null'>  work_company  = #{c.workCompany}, " +
            "</if> " +
            " <if test='c.companyProperty != null'> company_property   = #{c.companyProperty}, " +
            "</if> " +
            " <if test='c.jobLevel!= null'> job_level= #{c.jobLevel}, " +
            "</if> " +
            " <if test='c.entryTime != null'>entry_time = #{c.entryTime }, " +
            "</if> " +
            " <if test='c.workingYears != null'>working_years = #{c.workingYears }, " +
            "</if> " +
            " <if test='c.enterpriseSize != null'> enterprise_size= #{c.enterpriseSize }, " +
            "</if> " +
            " <if test='c.enterprisePhone != null'> enterprise_phone= #{c.enterprisePhone }, " +
            "</if> " +
            " <if test='c.enterpriseAddress != null'>enterprise_address= #{c.enterpriseAddress }, " +
            "</if> " +
            " <if test='c.enterpriseDetailAddress  != null'>enterprise_detail_address = #{c.enterpriseDetailAddress }, " +
            "</if> " +
            " <if test='c.monthlySalary  != null'> monthly_salary = #{c.monthlySalary }, " +
            "</if> " +
            " <if test='c.payMethod  != null'> pay_method = #{c.payMethod }, " +
            "</if> " +
            " <if test='c.payday   != null'> payday  = #{c.payday  }, " +
            "</if> " +
            " <if test='c.otherIncome   != null'> other_income  = #{c.otherIncome  }, " +
            "</if> " +
            " <if test='c.companyType   != null'> company_type  = #{c.companyType  }, " +
            "</if> " +
            " <if test='c.establishedTime   != null'> established_time  = #{c.establishedTime  }, " +
            "</if> " +
            " <if test='c.familyMonthlyIncome   != null'> family_monthly_income  = #{c.familyMonthlyIncome  }, " +
            "</if> " +
            " <if test='c.monthlyIncomeOfSpouse   != null'> monthly_income_of_spouse  = #{c.monthlyIncomeOfSpouse  }, " +
            "</if> " +
            " <if test='c.customerMonthlyIncome   != null'> customer_monthly_income  = #{c.customerMonthlyIncome  }, " +
            "</if> " +
            " <if test='c.familyMonthlyExpen   != null'>  family_monthly_expen  = #{c.familyMonthlyExpen  }, " +
            "</if> " +
            " <if test='c.totalFamilyAssets   != null'>  total_family_assets  = #{c.totalFamilyAssets  }, " +
            "</if> " +
            " <if test='c.totalHouseholdDebt   != null'>  total_household_debt  = #{c.totalHouseholdDebt  }, " +
            "</if> " +
            " <if test='c.isFamilyKnowLoan != null'>   is_family_know_loan  = #{c.isFamilyKnowLoan  }, " +
            "</if> " +
            " <if test='c.spouseName != null'>spouse_name = #{c.spouseName  }, " +
            "</if> " +
            " <if test='c.spousePhone != null'> spouse_phone = #{c.spousePhone  }, " +
            "</if> " +
            " <if test='c.spouseIdentityNumber != null'> spouse_identity_number = #{c.spouseIdentityNumber  }, " +
            "</if> " +
            " <if test='c.spouseEnterpriseAddress != null'> spouse_enterprise_address = #{c.spouseEnterpriseAddress}, " +
            "</if> " +
            " <if test='c.spouseIncome != null'> spouse_income = #{c.spouseIncome }, " +
            "</if> " +
            " <if test='c.immediateFamilyMemberName    != null'> immediate_family_member_name = #{c.immediateFamilyMemberName }, " +
            "</if> " +
            " <if test='c.commonContactName!= null'>  common_contact_name = #{c.commonContactName}, " +
            "</if> " +
            " <if test='c.immediateFamilyMemberPhone!= null'>  immediate_family_member_phone = #{c.immediateFamilyMemberPhone}, " +
            "</if> " +
            " <if test='c.immediateFamilyMemberCompanyAddress!= null'> immediate_family_member_company_address = #{c.immediateFamilyMemberCompanyAddress}, " +
            "</if> " +
            " <if test='c.commonContactPhone!= null'> common_contact_phone = #{c.commonContactPhone}, " +
            "</if> " +
            " <if test='c.commonContactCompanyAddress!= null'> common_contact_company_address = #{c.commonContactCompanyAddress}, " +
            "</if> " +
            " <if test='c.fkProductId != null'>fk_product_id  = #{c.fkProductId}, " +
            "</if> " +
            " </set> " +
            "where id=#{c.id} " +
            "</script>")
          int updateCustomer(@Param("c") CustomerInfo customerInfo );


           @Update("update customer_info set status=1 where id=#{id}")
           int updateStatus( long id);

           @Update("update customer_info set remarks=#{d.remarks} where id=#{d.id}")
           int updateRemark(@Param("d") DtoCus dtoCus);
}
